// 滚动到顶部
export const scrollToTop = () => window.scrollTo({top: 0, behavior: 'smooth'})
// 滚动到底部
export const scrollToBottom = () => window.scrollTo({top: document.body.scrollHeight, behavior: 'smooth'})

// 滚动半屏
export const scrollHalf = (direction: 1 | -1 = 1) => window.scrollBy({
    top: window.innerHeight / 2 * direction,
    behavior: 'smooth' // 可选，平滑滚动效果
});

// 滚动指定id 的元素, 元素顶部对齐窗口顶部
export const scrollToElement = (id: string) => {
    const element = document.getElementById(id);
    if (element) {
        element.scrollIntoView({behavior: 'smooth', block: 'start'});
    }
}

export const scrollToElementBatch = (id: string) => {
    scrollToElement(id)
    setTimeout(() => scrollToElement(id), 500);
    setTimeout(() => scrollToElement(id), 1000);
}